package io.renren.controller;

import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.utils.Result;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.dto.MarketmxDTO;
import io.renren.service.MarketmxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


/**
 * 市场监管明细表
 *
 * @author 罗胜平 781757616@qq.com
 * @since 1.0.0 2019-11-22
 */
@RestController
@RequestMapping("api/marketmx")
@Api(tags="市场监管")
public class MarketmxController {
    @Autowired
    private MarketmxService marketmxService;

    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    public Result<PageData<MarketmxDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<MarketmxDTO> page = marketmxService.page(params);

        return new Result<PageData<MarketmxDTO>>().ok(page);
    }

    @PostMapping("savaUnitPrice")
    @ApiOperation("保存")
    public Result savaUnitPrice(@RequestBody MarketmxDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        marketmxService.savaUnitPrice(dto);

        return new Result();
    }

    @GetMapping("selectDetails")
    @ApiOperation("详细信息")
    public Result<List<MarketmxDTO>> selectDetails(Long marketmxId ) {
        List<MarketmxDTO> data = marketmxService.selectDetails(marketmxId);
            return new Result<List<MarketmxDTO>>().ok(data); //
    }

    @GetMapping("slectPages")
    @ApiOperation("监管列表")
    public Result<List<MarketmxDTO>> slectPage() {
        List<MarketmxDTO> data = marketmxService.slectPages();
        return new Result<List<MarketmxDTO>>().ok(data); //
    }
    @GetMapping("slectCompare")
    @ApiOperation("监管对比列表")
    public Result<Map> slectCompare(MarketmxDTO dto) {
       Map data = marketmxService.slectCompare(dto);
        return new Result<Map>().ok(data); //
    }

}